#pragma once
#ifndef _CARD_INTERACTION_XML_MANAGER_H_
#define _CARD_INTERACTION_XML_MANAGER_H_
#define TIXML_USE_STL
#include "tinyxml.h"
#include "singleton.h"
#include <vector>
#define GET_INT_MEM(node_name, elem_name, attr)\
	int Get##node_name##elem_name##attr() \
{ 	node = doc->FirstChild(#node_name); \
	TiXmlElement *element = node->ToElement();\
	node = element->FirstChild(#elem_name);\
	element = node->ToElement();\
	int result = 0;\
	element->QueryIntAttribute(#attr, &result);\
	return result;\
}

#define GET_FLOAT_MEM(node_name, elem_name, attr)\
	float Get##node_name##elem_name##attr() \
{ 	node = doc->FirstChild(#node_name); \
	TiXmlElement *element = node->ToElement();\
	node = element->FirstChild(#elem_name);\
	element = node->ToElement();\
	float result = 0;\
	element->QueryFloatAttribute(#attr, &result);\
	return result;\
}
class XMLManager :public Singleton<XMLManager>
{
public:
	XMLManager(const char* fileName);
	~XMLManager();
	GET_FLOAT_MEM(Global,BirdSpeed,Value)
	GET_FLOAT_MEM(Global,CollThreshold,Value)
	GET_FLOAT_MEM(Global,BeizerSpeed,Value)
	GET_FLOAT_MEM(Global,Approaching,Value)
	GET_FLOAT_MEM(Global,UpWall,Value)
	GET_FLOAT_MEM(Global,BottomWall,Value)
	GET_FLOAT_MEM(Global,BirdMoveLength,Value)
	GET_FLOAT_MEM(Global,EffectTime,Value)

	GET_INT_MEM(Global,BirdReadyFlyNumFrame,Value)
	GET_INT_MEM(Global,BirdFlyingNumFrame,Value)
	GET_INT_MEM(Global,BirdSafelyNumFrame,Value)
	GET_INT_MEM(Global,BirdCatchedNumFrame,Value)
	GET_INT_MEM(Global,BirdWinNumFrame,Value)
	GET_INT_MEM(Global,EagleLoseNumFrame,Value)

	GET_INT_MEM(Global,BirdCounts,Value)
	GET_INT_MEM(Global,BirdDepressNumFrame,Value)
protected:
	bool Load(const char *filename);
	void Save();
	std::string  ConvertToString(char *str,int i);
private:
	TiXmlDocument  *doc;
	TiXmlNode      *node;
};
#endif